package experiment11;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;


public class No_3 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        BorderPane pane=new BorderPane();
        HBox info_box=new HBox();
        HBox button_box=new HBox();

        TextField num1=new TextField();
        TextField num2=new TextField();
        TextField result=new TextField();

        info_box.getChildren().addAll(new Label("number1"),num1,new Label("number2")
        ,num2,new Label("result"),result);

        Button plus=new Button("plus");
        Button subtract=new Button("subtract");
        Button multiply=new Button("multiply");
        Button divide=new Button("divide");

        plus.setOnAction(event -> {
            result.setText(String.valueOf(Double.parseDouble(num1.getText())+Double.parseDouble(num2.getText())));
        });
        subtract.setOnAction(event -> {
            result.setText(String.valueOf(Double.parseDouble(num1.getText())-Double.parseDouble(num2.getText())));
        });
        multiply.setOnAction(event -> {
            result.setText(String.valueOf(Double.parseDouble(num1.getText())*Double.parseDouble(num2.getText())));
        });
        divide.setOnAction(event -> {
            result.setText(String.valueOf(Double.parseDouble(num1.getText())/Double.parseDouble(num2.getText())));
        });
        button_box.getChildren().addAll(plus,subtract,multiply,divide);

        pane.setTop(info_box);
        pane.setBottom(button_box);

        primaryStage.setTitle("计算器");
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
    }
}
